<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="75px">
      <el-form-item label="作业名称" prop="workName">
        <el-select v-model="queryParams.workName" placeholder="请选择作业名称" style="width:160px;" clearable size="small">
          <el-option
            v-for="dict in workNameOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"

          />
        </el-select>
      </el-form-item>
      <el-form-item label="条码编号" prop="contNo">
        <el-input
          v-model="queryParams.contNo"
          placeholder="请输入条码编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
          style="width:200px;"
        />
      </el-form-item>
      <el-form-item label="BCR编号" prop="bcr">
        <el-input
          v-model="queryParams.bcr"
          placeholder="请输入BCR编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
          style="width:140px;"
        />
      </el-form-item>
      <el-form-item label="分拣状态" prop="fjzht">
        <el-input
          v-model="queryParams.fjzht"
          placeholder="请输入分拣状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
          style="width:140px;"
        />
      </el-form-item>
      <el-form-item label="目的地" prop="curPos">
        <el-input
          v-model="queryParams.curPos"
          placeholder="请输入目的地"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
          style="width:140px;"
        />
      </el-form-item>
      <!-- <el-form-item label="执行信息" prop="workMsg">
        <el-input
          v-model="queryParams.workMsg"
          placeholder="请输入执行信息"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
          style="width:160px;"
        />
      </el-form-item> -->

      <el-form-item label="创建时间">
        <el-date-picker
                v-model="dateRange"
                size="small"
                style="width: 350px"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>



      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:WorkLog:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>
<!--    v-hasPermi="['system:WorkLog:export']"-->
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:WorkLog:edit']"
        >详情</el-button>
      </el-col> -->

<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:WorkLog:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="WorkLogList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:WorkLog:edit']"
          >详情</el-button>
        </template>
      </el-table-column>

      <!-- <el-table-column label="ID" align="center" prop="workId" /> -->
      <el-table-column label="日志类型" align="center" prop="workName" min-width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="条码编号" align="center" prop="contNo" min-width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="实际目的地" align="center" prop="curPos" min-width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="wms分配目的地" align="center" prop="plcStataid5" min-width="140" :show-overflow-tooltip="true" />
      <el-table-column label="BCR编号" align="center" prop="bcr" />
      <el-table-column label="分拣状态" align="center" prop="fjzht" />
      <el-table-column label="包裹号" align="center" prop="plcStataid" min-width="140" :show-overflow-tooltip="true" />
      <el-table-column label="间距" align="center" prop="plcStataid1" min-width="140" :show-overflow-tooltip="true" />
      <el-table-column label="wms响应码" align="center" prop="plcStataid2" min-width="140" :show-overflow-tooltip="true" />
      <el-table-column label="wms响应时间" align="center" prop="plcStataid3" min-width="140" :show-overflow-tooltip="true" />
      <el-table-column label="整体耗时" align="center" prop="plcStataid4" min-width="140" :show-overflow-tooltip="true" />
      <el-table-column label="重量(Kg)" align="center" prop="weight" :show-overflow-tooltip="true"/>
      <el-table-column label="执行函数" align="center" prop="workProc" min-width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="创建时间" align="center" prop="creaTime" width="160" :show-overflow-tooltip="true">
        <template slot-scope="scope">
            <span>{{ parseTime(scope.row.creaTime) }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column label="执行信息" align="center" prop="workMsg" min-width="500" :show-overflow-tooltip="true"/>
      <el-table-column label="执行代码" align="center" prop="workRev" min-width="500" :show-overflow-tooltip="true"/> -->

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改跟踪日志对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="作业名称" prop="workName">
          <el-input v-model="form.workName" placeholder="请输入作业名称" />
        </el-form-item>
         <el-form-item label="BCR编号" prop="bcr">
          <el-input v-model="form.bcr" placeholder="请输入BCR编号" />
        </el-form-item>
        <el-form-item label="跟踪状态" prop="fjzht">
          <el-input v-model="form.fjzht" placeholder="请输入跟踪状态" />
        </el-form-item>
        <el-form-item label="条码编号" prop="contNo">
          <el-input v-model="form.contNo" placeholder="请输入条码编号" />
        </el-form-item>
        <el-form-item label="目的地" prop="curPos">
          <el-input v-model="form.curPos" placeholder="请输入目的地" />
        </el-form-item>
        <el-form-item label="重量(Kg)" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入重量(Kg)" />
        </el-form-item>
        <el-form-item label="执行函数" prop="workProc">
          <el-input v-model="form.workProc" placeholder="请输入执行函数" />
        </el-form-item>
        <el-form-item label="执行信息" prop="workMsg">
          <el-input type="textarea" v-model="form.workMsg" placeholder="请输入执行信息" />
        </el-form-item>
        <el-form-item label="代码回复" prop="workNo">
          <el-input type="textarea" v-model="form.workNo" placeholder="请输入代码回复" />
        </el-form-item>
        <el-form-item label="JSON反馈" prop="workPerNo">
          <el-input type="textarea" v-model="form.workPerNo" placeholder="请输入JSON反馈" />
        </el-form-item>
        <el-form-item label="执行代码" prop="workRev">
          <el-input type="textarea" v-model="form.workRev" placeholder="请输入执行代码" />
        </el-form-item>
        <!-- <el-form-item label="箱长" prop="plcStataid">
          <el-input v-model="form.plcStataid" placeholder="请输入箱长" />
        </el-form-item>
        <el-form-item label="间距1" prop="plcStataid1">
          <el-input v-model="form.plcStataid1" placeholder="请输入间距1" />
        </el-form-item>
        <el-form-item label="间距2" prop="plcStataid2">
          <el-input v-model="form.plcStataid2" placeholder="请输入间距2" />
        </el-form-item>
        <el-form-item label="间距3" prop="plcStataid3">
          <el-input v-model="form.plcStataid3" placeholder="请输入间距3" />
        </el-form-item>
        <el-form-item label="间距4" prop="plcStataid4">
          <el-input v-model="form.plcStataid4" placeholder="请输入间距4" />
        </el-form-item>
        <el-form-item label="间距5" prop="plcStataid5">
          <el-input v-model="form.plcStataid5" placeholder="请输入间距5" />
        </el-form-item> -->
      </el-form>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import { listWorkLog, getWorkLog, delWorkLog, addWorkLog, updateWorkLog, exportWorkLog } from "@/api/system/WorkLog";

export default {
  name: "WorkLog",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 跟踪日志表格数据
      WorkLogList: [],
        // 日期范围
        dateRange: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // ID字典
      workIdOptions: [],
      // 作业名称字典
      workNameOptions: [],
      // 条码字典
      contNoOptions: [],
      // mCONT_NO字典
      mcontNoOptions: [],
      // wellenCode字典
      wellencodeOptions: [],
      // 目的地字典
      curPosOptions: [],
      // WORK_CODE字典
      workCodeOptions: [],
      // 执行信息字典
      workMsgOptions: [],
      // WORK_PROC字典
      workProcOptions: [],
      // 创建时间字典
      creaTimeOptions: [],
      // WORK_SEC字典
      workSecOptions: [],
      // WORK_PER_NO字典
      workPerNoOptions: [],
      // WORK_PER_NAME字典
      workPerNameOptions: [],
      // 分拣状态字典
      fjzhtOptions: [],
      // BCR字典
      bcrOptions: [],
      // work_no字典
      workNoOptions: [],
      // 重量字典
      weightOptions: [],
      // WORK_REV字典
      workRevOptions: [],
      // 箱长字典
      plcStataidOptions: [],
      // 间距1字典
      plcStataid1Options: [],
      // 间距2字典
      plcStataid2Options: [],
      // 间距3字典
      plcStataid3Options: [],
      // 间距4字典
      plcStataid4Options: [],
      // 间距5字典
      plcStataid5Options: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workName: null,
        contNo: null,
        mcontNo: null,
        wellencode: null,
        curPos: null,
        workCode: null,
        workMsg: null,
        workProc: null,
        creaTime: null,
        workSec: null,
        workPerNo: null,
        workPerName: null,
        fjzht: null,
        bcr: null,
        workNo: null,
        weight: null,
        workRev: null,
        plcStataid: null,
        plcStataid1: null,
        plcStataid2: null,
        plcStataid3: null,
        plcStataid4: null,
        plcStataid5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("${column.dictType}").then(response => {
      this.workIdOptions = response.data;
    });
    this.getDicts("workName_type").then(response => {
      this.workNameOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.contNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.mcontNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.wellencodeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.curPosOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.workCodeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.workMsgOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.workProcOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.creaTimeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.workSecOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.workPerNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.workPerNameOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.fjzhtOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.bcrOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.workNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.weightOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.workRevOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.plcStataidOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.plcStataid1Options = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.plcStataid2Options = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.plcStataid3Options = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.plcStataid4Options = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.plcStataid5Options = response.data;
    });
  },
  methods: {
    /** 查询跟踪日志列表 */
    getList() {
      this.loading = true;
              listWorkLog(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
        this.WorkLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // ID字典翻译
    workIdFormat(row, column) {
      return this.selectDictLabel(this.workIdOptions, row.workId);
    },
    // 作业名称字典翻译
    workNameFormat(row, column) {
      return this.selectDictLabel(this.workNameOptions, row.workName);
    },
    // 条码字典翻译
    contNoFormat(row, column) {
      return this.selectDictLabel(this.contNoOptions, row.contNo);
    },
    // mCONT_NO字典翻译
    mcontNoFormat(row, column) {
      return this.selectDictLabel(this.mcontNoOptions, row.mcontNo);
    },
    // wellenCode字典翻译
    wellencodeFormat(row, column) {
      return this.selectDictLabel(this.wellencodeOptions, row.wellencode);
    },
    // 目的地字典翻译
    curPosFormat(row, column) {
      return this.selectDictLabel(this.curPosOptions, row.curPos);
    },
    // WORK_CODE字典翻译
    workCodeFormat(row, column) {
      return this.selectDictLabel(this.workCodeOptions, row.workCode);
    },
    // 执行信息字典翻译
    workMsgFormat(row, column) {
      return this.selectDictLabel(this.workMsgOptions, row.workMsg);
    },
    // WORK_PROC字典翻译
    workProcFormat(row, column) {
      return this.selectDictLabel(this.workProcOptions, row.workProc);
    },
    // 创建时间字典翻译
    creaTimeFormat(row, column) {
      return this.selectDictLabel(this.creaTimeOptions, row.creaTime);
    },
    // WORK_SEC字典翻译
    workSecFormat(row, column) {
      return this.selectDictLabel(this.workSecOptions, row.workSec);
    },
    // WORK_PER_NO字典翻译
    workPerNoFormat(row, column) {
      return this.selectDictLabel(this.workPerNoOptions, row.workPerNo);
    },
    // WORK_PER_NAME字典翻译
    workPerNameFormat(row, column) {
      return this.selectDictLabel(this.workPerNameOptions, row.workPerName);
    },
    // 分拣状态字典翻译
    fjzhtFormat(row, column) {
      return this.selectDictLabel(this.fjzhtOptions, row.fjzht);
    },
    // BCR字典翻译
    bcrFormat(row, column) {
      return this.selectDictLabel(this.bcrOptions, row.bcr);
    },
    // work_no字典翻译
    workNoFormat(row, column) {
      return this.selectDictLabel(this.workNoOptions, row.workNo);
    },
    // 重量字典翻译
    weightFormat(row, column) {
      return this.selectDictLabel(this.weightOptions, row.weight);
    },
    // WORK_REV字典翻译
    workRevFormat(row, column) {
      return this.selectDictLabel(this.workRevOptions, row.workRev);
    },
    // 箱长字典翻译
    plcStataidFormat(row, column) {
      return this.selectDictLabel(this.plcStataidOptions, row.plcStataid);
    },
    // 间距1字典翻译
    plcStataid1Format(row, column) {
      return this.selectDictLabel(this.plcStataid1Options, row.plcStataid1);
    },
    // 间距2字典翻译
    plcStataid2Format(row, column) {
      return this.selectDictLabel(this.plcStataid2Options, row.plcStataid2);
    },
    // 间距3字典翻译
    plcStataid3Format(row, column) {
      return this.selectDictLabel(this.plcStataid3Options, row.plcStataid3);
    },
    // 间距4字典翻译
    plcStataid4Format(row, column) {
      return this.selectDictLabel(this.plcStataid4Options, row.plcStataid4);
    },
    // 间距5字典翻译
    plcStataid5Format(row, column) {
      return this.selectDictLabel(this.plcStataid5Options, row.plcStataid5);
    },
    // 取消按钮
    // cancel() {
    //   this.open = false;
    //   this.reset();
    // },
    // 表单重置
    reset() {
      this.form = {
        workId: null,
        workName: null,
        contNo: null,
        mcontNo: null,
        wellencode: null,
        curPos: null,
        workCode: null,
        workMsg: null,
        workProc: null,
        creaTime: null,
        workSec: null,
        workPerNo: null,
        workPerName: null,
        fjzht: null,
        bcr: null,
        workNo: null,
        weight: null,
        workRev: null,
        plcStataid: null,
        plcStataid1: null,
        plcStataid2: null,
        plcStataid3: null,
        plcStataid4: null,
        plcStataid5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.workId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加跟踪日志";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const workId = row.workId || this.ids
      getWorkLog(workId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改跟踪日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.workId != null) {
            updateWorkLog(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addWorkLog(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workIds = row.workId || this.ids;
      this.$confirm('是否确认删除跟踪日志编号为"' + workIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWorkLog(workIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有跟踪日志数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportWorkLog(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
